package com.xin.jdbc_utils;

import java.sql.*;

public class DBUtil {

    private DBUtil() {
    }

    static {
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    public static  Connection getConnection() throws Exception{
        return DriverManager.getConnection("jdbc:mysql://localhost:3306/student_manage","root","856736");
    }
    public static void close(Connection conn, Statement sta, ResultSet re){
        //思考一下这里抛出异常为什么不行？？
        if(re!=null){
            try {
                re.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }if(sta!=null){
            try {
                sta.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }if(conn!=null){
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

}
